﻿@using WD.Db.Contract;
@model User
@{
    ViewBag.Title = "WD.Db.Contract.User_Create";
    Layout = "~/Views/Shared/_LayoutEdit.cshtml";

}

<script src="~/Content/Script/geo.js"></script>
<style>
    .radio-inline { margin-top: 0 !important; }
    .procity .error { border-color: red; }
        .procity .error:after { color: red; }
    .checkcs { border-color: red; }
</style>

<form id="SetUserProfit_mainForm" action="@Url.Action("SetProfit", "User")" method="POST">

    @Html.HiddenFor(model => model.ID)
    <div class="form-group col-xs-6 ">
        @Html.LabelFor(model => model.UserId, "登录名", new { @class = "" })

        @Html.TextBoxFor(model => model.UserId, new { @class = "form-control", disabled = "true" })
    </div>
    <div class="form-group col-xs-6 ">
        @Html.LabelFor(model => model.Name, "用户名", new { @class = "" })

        @Html.TextBoxFor(model => model.Name, new { @class = "form-control", disabled = "true" })
    </div>

    <div class="form-group col-xs-12 ">
        <label>代理类别</label>
        <input type="text" name="agentType" id="agentType" value=" " hidden="hidden" />
        <span id="checklist" class="form-control">
            <label class="radio-inline">
                <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="@CommonCode.区域角色_省级代理"> 省级代理
            </label>
            <label class="radio-inline">
                <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="@CommonCode.区域角色_市级代理"> 市级代理
            </label>
            <label class="radio-inline">
                <input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="@CommonCode.区域角色_区级代理"> 区级代理
            </label>
        </span>
    </div>

    <div class="form-group col-xs-12 ">
        <label>地区</label>

        <span class="form-control procity">
            <select name="Pro" id="Pro"></select>
            <select name="City" id="City"></select>
            <select name="Dis" id="Dis"></select>
        </span>
    </div>
    @if (Model.IsAgent != null && Model.IsAgent > 0)
    {

        <div style="text-align:right;width:100%">

            <a href="@Url.Action("cancelProfit", new { id = Model.ID })" class="btn btn-danger" id="agentCancel" target="ajax" data-reload="true">取消代理</a>
        </div>

    }
</form>

<div class="clearfix"></div>

<script>
    setup();


    //选择代理种类
    $("[name=inlineRadioOptions]").click(function () {
        $("#checklist").removeClass("checkcs");
        $("#Pro").hide();
        $("#City").hide();
        $("#Dis").hide();
        var typeNo = $(this).val();
        if (typeNo == '@(CommonCode.区域角色_省级代理)') {
            $("#Pro").show();
        } else if (typeNo == '@(CommonCode.区域角色_市级代理)') {
            $("#Pro").show();
            $("#City").show();
        } else if (typeNo == '@(CommonCode.区域角色_区级代理)') {
            $("#Pro").show();
            $("#City").show();
            $("#Dis").show();
        }
    });


    function SetUserProfitCheckField() {
        //TODO 检查字段必填项 必须有返回值（成功TRUE,失败FALSE）

        //是否选择代理类型
        if (!$(".radio-inline").find("input").is(":checked")) {
            $("#checklist").addClass("checkcs");
            return false;
        }

        var inputChecked = $("[name=inlineRadioOptions]:checked");
        var typeNo = inputChecked.val();
        if (typeNo == '@(CommonCode.区域角色_省级代理)') {
            if ($("#Pro").val() == "省份") {
                $("#Pro").addClass("error").click(function () {
                    $(this).removeClass("error");
                });
                return false;
            }
        }

        if (typeNo == '@(CommonCode.区域角色_市级代理)') {
            if ($("#City").val() == "地级市") {
                $("#City").addClass("error").click(function () {
                    $(this).removeClass("error");
                });
                return false;
            }
        }

        if (typeNo == '@(CommonCode.区域角色_区级代理)') {
            if ($("#Dis").val() == "市、县级市、县") {
                $("#Dis").addClass("error").click(function () {
                    $(this).removeClass("error");
                });
                return false;
            }
        }

        $("#agentType").val(typeNo);

        return true;
    }

</script>
